home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2018 January / PCgo 01-2018 CD-ROM Germany.iso / nw.pak / Unnamed File 000148.txt < prev    next >
Encoding:
Text File  |  2015-07-29  |  2.9 KB  |  116 lines

  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. /**
  6.  * @fileoverview This is a table column representation
  7.  */
  8.  
  9. cr.define('cr.ui.table', function() {
  10.   /** @const */ var EventTarget = cr.EventTarget;
  11.  
  12.   /**
  13.    * A table column that wraps column ids and settings.
  14.    * @param {string} id
  15.    * @param {string} name
  16.    * @param {number} width
  17.    * @param {boolean=} opt_endAlign
  18.    * @constructor
  19.    * @extends {cr.EventTarget}
  20.    */
  21.   function TableColumn(id, name, width, opt_endAlign) {
  22.     this.id_ = id;
  23.     this.name_ = name;
  24.     this.width_ = width;
  25.     this.endAlign_ = !!opt_endAlign;
  26.   }
  27.  
  28.   TableColumn.prototype = {
  29.     __proto__: EventTarget.prototype,
  30.  
  31.     defaultOrder_: 'asc',
  32.  
  33.     /**
  34.      * Clones column.
  35.      * @return {cr.ui.table.TableColumn} Clone of the given column.
  36.      */
  37.     clone: function() {
  38.       var tableColumn = new TableColumn(this.id_, this.name_, this.width_,
  39.                                         this.endAlign_);
  40.       tableColumn.renderFunction = this.renderFunction_;
  41.       tableColumn.headerRenderFunction = this.headerRenderFunction_;
  42.       tableColumn.defaultOrder = this.defaultOrder_;
  43.       return tableColumn;
  44.     },
  45.  
  46.     /**
  47.      * Renders table cell. This is the default render function.
  48.      * @param {*} dataItem The data item to be rendered.
  49.      * @param {string} columnId The column id.
  50.      * @param {cr.ui.Table} table The table.
  51.      * @return {HTMLElement} Rendered element.
  52.      */
  53.     renderFunction_: function(dataItem, columnId, table) {
  54.       var div = /** @type {HTMLElement} */
  55.           (table.ownerDocument.createElement('div'));
  56.       div.textContent = dataItem[columnId];
  57.       return div;
  58.     },
  59.  
  60.     /**
  61.      * Renders table header. This is the default render function.
  62.      * @param {cr.ui.Table} table The table.
  63.      * @return {Text} Rendered text node.
  64.      */
  65.     headerRenderFunction_: function(table) {
  66.       return table.ownerDocument.createTextNode(this.name);
  67.     },
  68.   };
  69.  
  70.   /**
  71.    * The column id.
  72.    * @type {string}
  73.    */
  74.   cr.defineProperty(TableColumn, 'id');
  75.  
  76.   /**
  77.    * The column name
  78.    * @type {string}
  79.    */
  80.   cr.defineProperty(TableColumn, 'name');
  81.  
  82.   /**
  83.    * The column width.
  84.    * @type {number}
  85.    */
  86.   cr.defineProperty(TableColumn, 'width');
  87.  
  88.   /**
  89.    * True if the column is aligned to end.
  90.    * @type {boolean}
  91.    */
  92.   cr.defineProperty(TableColumn, 'endAlign');
  93.  
  94.   /**
  95.    * The column render function.
  96.    * @type {function(*, string, cr.ui.Table): HTMLElement}
  97.    */
  98.   cr.defineProperty(TableColumn, 'renderFunction');
  99.  
  100.   /**
  101.    * The column header render function.
  102.    * @type {function(cr.ui.Table): Text}
  103.    */
  104.   cr.defineProperty(TableColumn, 'headerRenderFunction');
  105.  
  106.   /**
  107.    * Default sorting order for the column ('asc' or 'desc').
  108.    * @type {string}
  109.    */
  110.   cr.defineProperty(TableColumn, 'defaultOrder');
  111.  
  112.   return {
  113.     TableColumn: TableColumn
  114.   };
  115. });
  116.